package com.hua.server.oauth.entity;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "tb_role")
@Getter
@Setter
public class Role extends BaseIDEntity {

    @Column(name = "parent_id",length = 28)
    private Integer parentId;

    @Column(name = "name",length = 64)
    private String name;

    @Column(name = "enname",length = 64)
    private String enName;

    @Column(name = "description",length = 128)
    private String description;

    @Column(name = "created")
    private LocalDateTime created;

    @Column(name = "updated")
    private LocalDateTime updated;

    @ManyToMany(mappedBy = "roles",cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    private Set<User> users;

    @ManyToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
    @JoinTable(name = "tb_role_permission",joinColumns = @JoinColumn(name = "role_id"),inverseJoinColumns = @JoinColumn(name = "permission_id"))
    private Set<Permission> permissions;
}
